
//页面加载事件
window.onload=function(){
   
    //btn按钮绑定点击事件
    document.getElementById("btn").onclick=function(){
        alert('点击按钮了');
    }

    //动态生成网页元素节点，动态添加事件
    var btn = document.createElement("input");//<input/>
    btn.setAttribute("type","button");//<input type="button" />
    btn.value="动态创建按钮";//<input type="button" value="动态创建按钮" />
    document.getElementById("myDiv").appendChild(btn);
    btn.onclick=function(){
        alert('点击按钮了');
    }

    //冒泡方式动态添加事件
    // document.getElementById("myDiv").onclick=function(){
    //     alert('div');
    // }
    // document.getElementById("myP").onclick=function(){
    //     alert('p');
    // }

    //事件监听方式动态添加事件
    document.getElementById("myDiv").addEventListener("click",function(event){
        alert('div');
        event.stopPropagation();
    },true);
    document.getElementById("myP").addEventListener("click",function(event){
        alert('p');
        //event.stopPropagation();
    },true);

    // document.getElementById("myDiv").onmousemove=function(){
    //     console.log("!");
    // }

    //window.onresize=test;

    // window.onresize=function(){
    //     console.log("!!!");
    // }

    // var num = 0;
    // window.onscroll=function(){
    //     num++;
    //     console.log(num);
    // }

    window.oncontextmenu=function(event){
        console.log(event.clientX, event.clientY);
        var box = document.getElementsByClassName("box")[0];
        box.style.left = event.clientX + "px";
        box.style.top = event.clientY + "px";  
        return false;
    }

    

}
function fn1(){
    alert('点击p标签调用点击事件');
}

function fn2(flag){
    alert(flag);
}

function fn3(){
    console.log("!");
}


function fn4(){
    console.log("#");
}

function checkItem(){
    //获取元素值
    var zh = document.getElementsByName("zhanghao")[0].value;
    //非空判断
    // var bl = '';
    // if(!bl){
    //     alert('bl是空值');
    // }
    if(!zh){
        alert("账号不能为空！"); 
    }
}

function checkForm(){
    //获取元素值
    var zh = document.getElementsByName("zhanghao")[0].value;
    if(!zh){
        alert("账号不能为空！");
        return false;
    }
    return true;
}

function test(){
    console.log(123);
}

//e   --> event
//obj --> this
function fn5(e,obj){
    // var zhi = document.getElementById("txt").value;
    // console.log(zhi);
    //console.log(obj.keyCode, obj.key);
    console.log(e);
    console.log(obj);
    if(e.keyCode == 13){
        if(obj.id == 'txt1'){
            document.getElementById("txt2").focus();
        }else if(obj.id == 'txt2'){
            document.getElementById("txt3").focus();
        }else if(obj.id == 'txt3'){
            document.getElementById("txt1").focus();
        }
    }
}

//e   --> event
//obj --> this
function fn6(e,obj){
    console.log(e);
    console.log(obj);
    console.log(e.clientX,e.clientY);
}
